<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller 
{
  	public function index()
		{
			if(!isset($_SESSION['userid']))
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
				}
			$t_agent=M('t_agent');	//代理表
			$t_login_record=M('t_login_record');	//登录记录表		
			$sql=$t_login_record->where('accounts='.$_SESSION['accounts'])->find();	//登录用户的信息
			//得到  当前数据库时间戳大于当前时间戳的数据
			$this->assign('User_Profile',$User_Profile);	//传递数组
			$this->assign('sql',$sql);
			$this->display();
		}
		/* 查询页面 */
	public function grabble()
	{
			if(!isset($_SESSION['accounts']))
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
				}
			
				$t_users= M('','t_users','DB_CONFIG1'); 
				$w=array();
				$count      = $t_users->where($w)->count();
				$Page       = new \Think\Page($count,25);
				$Page->setConfig('header','上一页');
				$Page->setConfig('next','下一页');

				$show       = $Page->show();
				$result = $t_users->where($w)->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();

				$this->assign('page',$show);			
			if($_POST)
			{
						$userid=$_POST['userid'];
						$name=$_POST['name'];
						$userid=$_POST['userid'];//接受POST数据
						$accounts=$_SESSION['accounts'];
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
					{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('请正确输入');history.go(-1)</script>";die;
					}

				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
					{
						$w['name']=array('like','%'.$name.'%');//把数据写到空数组去
						$w['userid']=array('like','%'.$userid.'%');//把数据写到空数组
						$result=$t_users->where($w)->select();
						if($result){
							$stat=0;
							M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,stat)values('$accounts','select','$stat')");
						}
						if($result=="")
						{
							echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
							echo "<script type='text/javascript'>alert('不存在');history.go(-1)</script>";die;
						}
					}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
					{
						$sdate=strtotime($_POST['sdate']); //POST来的时间转为时间戳
						$edate=strtotime($_POST['edate']);	//POST来的时间转为时间戳
						$arr['regtime']=array('egt',$sdate);	//判断小于等于起始时间的条件
						$arr['regtime']=array('elt',$edate);//判断大于等于起始时间的条件
						$result=M('t_agent')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();
						if($result){
							$stat=0;
							M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,stat)values('$accounts','select','$stat')");
						}
					}
			}	
			$this->assign('result',$result);
			$this->display();
	}

				 /* 在线用户页面 没有状态显示，所以无法读出 */ 
	public function sinfo()
	{
	
		$this->display();	
	}
	/*      修改密码           */
	public function modipass()
	{
			if(!isset($_SESSION['accounts']))
			{
				echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
				echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";die;
			}
			$t_agent= M('','t_agent','DB_CONFIG0'); 
			if(IS_POST)
			{
				if($_POST['password']=="" || $_POST['passwordd']==""){
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('
					密码不能为空');history.go(-1)</script>";
				}
				if($password!=$passwordd)
				{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('您输入的新密码和确认密码不一致，请重新输入');history.go(-1)</script>";
				}
					if(MD5($_POST['password'])==MD5($_POST['passwordd']))
					{
						$t_agent->password=MD5($_POST['password']);
						$new_password=$t_agent->where('userid='.$_SESSION['userid'])->save();						
						if($new_password){
							$stat=0;
							$accounts=$_SESSION['accounts'];
							M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,stat)values('$accounts','密码','$stat')");
						}
					if($new_password)
					{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('密码重置成功，请保管好您的密码。');location.href='".U('Login/login')."'</script>";
					}else{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('系统繁忙，请您重再次输入');history.go(-1)</script>";
						}
					}
			}
		$this->display();
	}
	/*   游戏记录  */
	public function loadgame()
	{
		if(!isset($_SESSION['accounts']))
			{
				echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
				echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";die;
			}
			$t_rooms= M('','t_rooms','DB_CONFIG1'); 
			$userid=I('get.userid');
			if($_GET['userid']!="")
			{
		$loadgame=$t_rooms->where('user_id0="'.$userid.'" || user_id1="'.$userid.'" || user_id2="'.$userid.'" || user_id3="'.$userid.'"')->select();
				}
			if($_GET['userid']==""){
				//分页查询
				$w=array();
				$count      = $t_rooms->where($w)->count();
				$Page       = new \Think\Page($count,25);
				$Page->setConfig('header','上一页');
				$Page->setConfig('next','下一页');
				$show       = $Page->show();
				$loadgame = $t_rooms->where($w)->order('user_id0 asc')->limit($Page->firstRow.','.$Page->listRows)->select();
						//接受POST数据
				$userid=$_POST['userid'];
				$name=$_POST['name'];
				$userid=$_POST['userid'];
						//判断条件 模糊查询
				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
					{
						$w['user_name0']=array('like','%'.$name.'%');//把数据写到空数组去     //此处又4个ID 现查的是第一个
						$w['user_id0']=array('like','%'.$userid.'%');//把数据写到空数组		  //同上!!!!!
						$loadgame=$t_rooms->where($w)->select();
					}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
					{
						$sdate=strtotime($_POST['sdate']); //POST来的时间转为时间戳
						$edate=strtotime($_POST['edate']);	//POST来的时间转为时间戳
						$arr['regtime']=array('egt',$sdate);	//判断小于等于起始时间的条件
						$arr['regtime']=array('elt',$edate);//判断大于等于起始时间的条件
						$loadgame=M('t_rooms')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
					}
					$this->assign('page',$show);
			}
					$this->assign('loadgame',$loadgame);
					$this->display();
	}
	public function playercharge(){
			if(!isset($_SESSION['accounts']))
			{
				echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
				echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
			}
		$t_donate= M('','t_donate','DB_CONFIG0');
		$t_users= M('','t_users','DB_CONFIG1');
		$loadgame=$t_donate->select();
		$this->assign('loadgame',$loadgame);
		$t_users= M('','t_users','DB_CONFIG1'); 
		$w=array();
		$count      = $t_users->where($w)->count();
		$Page       = new \Think\Page($count,25);
		$Page->setConfig('header','上一页');
		$Page->setConfig('next','下一页');
		$show       = $Page->show();
		$result = $t_users->where($w)->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
				//接受POST数据
		$userid=$_POST['userid'];
		$name=$_POST['name'];
		$userid=$_POST['userid'];
		if(IS_POST)
		{//dump($_POST);die;
			if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['benefactor']=array('like','%'.$userid.'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$name.'%');//把数据写到空数组		
				$loadgame=$t_donate->where($w)->select();
				//dump($loadgame);die;
			}	
			if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=strtotime($_POST['sdate']); //POST来的时间转为时间戳
				$edate=strtotime($_POST['edate']);	//POST来的时间转为时间戳
				$arr['regtime']=array('egt',$sdate);	//判断小于等于起始时间的条件
				$arr['regtime']=array('elt',$edate);//判断大于等于起始时间的条件
				$loadgame=M('t_donate')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
			}
		}
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
	public function recharge()
	{
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		echo '未有此表记录';die;
		$t_donate= M('','t_donate','DB_CONFIG0');
		$t_users= M('','t_users','DB_CONFIG1');
		$loadgame=$t_donate->select();
		$this->assign('loadgame',$loadgame);
		$t_users= M('','t_users','DB_CONFIG1'); 
		$w=array();
		$count      = $t_users->where($w)->count();
		$Page       = new \Think\Page($count,25);
		$Page->setConfig('header','上一页');
		$Page->setConfig('next','下一页');
		$show       = $Page->show();
		$result = $t_users->where($w)->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
				//接受POST数据
		$userid=$_POST['userid'];
		$name=$_POST['name'];
		$userid=$_POST['userid'];
		if(IS_POST)
			{//dump($_POST);die;
				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
				{
					$w['benefactor']=array('like','%'.$userid.'%');//把数据写到空数组去  
					$w['name']=array('like','%'.$name.'%');//把数据写到空数组		
					$loadgame=$t_donate->where($w)->select();
					//dump($loadgame);die;
				}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
				{
					$sdate=strtotime($_POST['sdate']); //POST来的时间转为时间戳
					$edate=strtotime($_POST['edate']);	//POST来的时间转为时间戳
					$arr['regtime']=array('egt',$sdate);	//判断小于等于起始时间的条件
					$arr['regtime']=array('elt',$edate);//判断大于等于起始时间的条件
					$loadgame=M('t_donate')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
				}
			}
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
	public function supervise()
	{
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$t_agent= M('','t_agent','DB_CONFIG0');
		$loadgame=$t_agent->where('referrer!=0')->select();
		$w=array();
		$count      = $t_agent->where($w)->count();
		$Page       = new \Think\Page($count,25);
		$Page->setConfig('header','上一页');
		$Page->setConfig('next','下一页');
		$show       = $Page->show();
		$result = $t_agent->where($w,'referrer!=0')->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
				//接受POST数据
		$userid=$_POST['userid'];
		$name=$_POST['name'];
		$userid=$_POST['userid'];
		if(IS_POST)
			{
				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
					{
						$w['accounts']=array('like','%'.$userid.'%');													//把数据写到空数组去  
						$w['username']=array('like','%'.$name.'%');														//把数据写到空数组		
						$loadgame=$t_agent->where($w,'referrer!=0')->select();
					}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
					{
						$sdate=strtotime($_POST['sdate']); 																//POST来的时间转为时间戳
						$edate=strtotime($_POST['edate']);																//POST来的时间转为时间戳
						$arr['regtime']=array('egt',$sdate);															//判断小于等于起始时间的条件
						$arr['regtime']=array('elt',$edate);															//判断大于等于起始时间的条件
						$loadgame=M('t_agent')->where($arr,'manner==1 AND referrer!=0')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
					}
			}
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
	public function relation()
	{
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$t_agent= M('','t_agent','DB_CONFIG0');
		$id=$_GET['userid'];
		$news=$t_agent->where('userid='.$id)->find();
		$loadgame=$t_agent->where('referrer='.$news['accounts'])->select();
		$w=array();
		$count      = $t_agent->where($w)->count();
		$Page       = new \Think\Page($count,25);
		$Page->setConfig('header','上一页');
		$Page->setConfig('next','下一页');
		$show       = $Page->show();
		$result = $t_agent->where($w)->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
				//接受POST数据
		$userid=$_POST['userid'];
		$name=$_POST['name'];
		$userid=$_POST['userid'];
		if(IS_POST)
			{
				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
					{
						$w['accounts']=array('like','%'.$userid.'%');														//把数据写到空数组去  
						$w['username']=array('like','%'.$name.'%');															//把数据写到空数组		
						$loadgame=$t_agent->where($w,'referrer='.$news['accounts'])->select();
					}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
					{
						$sdate=strtotime($_POST['sdate']); 																	//POST来的时间转为时间戳
						$edate=strtotime($_POST['edate']);																	//POST来的时间转为时间戳
						$arr['regtime']=array('egt',$sdate);																//判断小于等于起始时间的条件
						$arr['regtime']=array('elt',$edate);																//判断大于等于起始时间的条件
						$loadgame=M('t_agent')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
					}
			}
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
	public function low()
	{
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$t_agent= M('','t_agent','DB_CONFIG0');
		$id=$_GET['userid'];
		$news=$t_agent->where('userid='.$id)->find();
		$loadgame=$t_agent->where('referrer='.$news['accounts'])->select();
		$w=array();
		$count      = $t_agent->where($w)->count();
		$Page       = new \Think\Page($count,25);
		$Page->setConfig('header','上一页');
		$Page->setConfig('next','下一页');
		$show       = $Page->show();
		$result = $t_agent->where($w)->order('userid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
		if(IS_POST)
		{
			if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['accounts']=array('like','%'.$_POST['userid'].'%');												//把数据写到空数组去  
				$w['username']=array('like','%'.$_POST['name'].'%');												//把数据写到空数组		
				$loadgame=$t_agent->where($w,'referrer='.$news['accounts'])->select();
			}	
			if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=strtotime($_POST['sdate']); 																	//POST来的时间转为时间戳
				$edate=strtotime($_POST['edate']);																	//POST来的时间转为时间戳
				$arr['regtime']=array('egt',$_POST['sdate']);														//判断小于等于起始时间的条件
				$arr['regtime']=array('elt',$_POST['edate']);														//判断大于等于起始时间的条件
				$loadgame=M('t_agent')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();//时间不符合    需要修正！！！！
			}
		}
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
	public function recordpay()
	{
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$presnted=M("","","DB_CONFIG0")->query("select * from t_presented");
			if(IS_POST)
			{
				if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
				{
					$w['benefactor']=array('like','%'.$_POST['userid'].'%');												//把数据写到空数组去  
					$w['recipient']=array('like','%'.$_POST['name'].'%');													//把数据写到空数组		
					$presnted=M('t_presented')->where($w)->select();														//echo M('t_presented')->_sql();die;
				}	
				if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
				{
					$sdate=strtotime($_POST['sdate']);																		//POST来的时间转为时间戳
					$edate=strtotime($_POST['edate']);																		//POST来的时间转为时间戳
					$arr['regtime']=array('egt',$_POST['sdate']);															//判断小于等于起始时间的条件
					$arr['regtime']=array('elt',$_POST['edate']);															//判断大于等于起始时间的条件
					$presnted=M('t_agent')->where($arr,'manner==1')->where('benefactor='.$_SESSION['accounts'])->select();  //时间不符合    需要修正！！！！
				}
			}
		$this->assign('presnted',$presnted);
		$this->display();
	}
	public function deduct()
	{
		
		if(!isset($_SESSION['accounts']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		
		if($_GET['userid']=="")
		{
			$deduct=M("","","DB_CONFIG0")->query('select * from t_agent where referrer=0');
			if(IS_POST)
			{
				if($_POST['rebate']<0 || $_POST['up_rebate']=="" || $_POST['up_rebate']<0 || $_POST['rebate']=="" || $_POST['limits']=="" || $_POST['limits']<0)
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请正确输入值');history.go(-1)</script>";die;
				}
				$rebate=$_POST['rebate'];
				$up_rebate=$_POST['up_rebate'];
				$limits=$_POST['limits'];
				if(M("","","DB_CONFIG0")->execute("update t_agent set limits='$limits' where referrer=0"))
				{
					M("","","DB_CONFIG0")->execute("update t_agent set up_rebate='$up_rebate' where referrer=0");
					M("","","DB_CONFIG0")->execute("update t_agent set rebate='$rebate' where referrer=0");
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('更改成功');history.go(-1)</script>";die;
				}
			}			
		}
		if($_GET['userid']!="")
		{
			$userid=$_GET['userid'];
			$deduct=M("","","DB_CONFIG0")->query('select * from t_agent where userid='.$userid);
			if(IS_POST)
			{
				if($_POST['rebate']<0 || $_POST['up_rebate']=="" || $_POST['up_rebate']<0 || $_POST['rebate']=="" || $_POST['limits']=="" || $_POST['limits']<0)
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请正确输入值');history.go(-1)</script>";die;
				}
				$rebate=$_POST['rebate'];
				$up_rebate=$_POST['up_rebate'];
				$limits=$_POST['limits'];
				
				if(M("","","DB_CONFIG0")->execute("update t_agent set limits='$limits' where userid=".$userid))
				{
					M("","","DB_CONFIG0")->execute("update t_agent set up_rebate='$up_rebate' where userid=".$userid);
					M("","","DB_CONFIG0")->execute("update t_agent set rebate='$rebate' where userid=".$userid);
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('更改成功');history.go(-1)</script>";die;
				}
			}			
		}$userid=$_GET['userid'];
		$this->assign('deduct',$deduct);
		$this->display();
	}
}





































































